package com.kingwang.training.designpattern.memento.bo.game;

import lombok.Data;

/**
 * 游戏玩家
 *
 * @author King
 */
@Data
public class GamePlayer {
    private int hp;

    private int exp;

    public GamePlayer(int hp, int exp) {
        this.hp = hp;
        this.exp = exp;
    }

    public void play(int hp, int exp) {
        this.hp -= hp;
        this.exp += exp;
    }

    /**
     * 保存至备忘录
     *
     * @return
     */
    public GameMemento saveToMemento() {
        return new GameMemento(this.hp, this.exp);
    }

    /**
     * 从备忘录恢复
     *
     * @param memento
     */
    public void restoreFromMemento(GameMemento memento) {
        this.hp = memento.getHp();
        this.exp = memento.getExp();
    }
}
